#!groovy

@Library('jenkinslib@master') _

// 使用参数代替硬编码值
def build = new org.devops.build()
def tools = new org.devops.tools()
def email = new org.devops.toemail()

String buildType  = "${env.buildType}"
String buildShell = "${env.buildShell}"
String branchName = "${env.branchName}"
String GIT_URL    = "${env.srcUrl}"
String userEmail  = "${env.userEmail}" // 使用环境变量代替硬编码

node('master') {

    stage('CODE') {
        sh 'pwd'
        
        dir('java_project') {
            script {
                println("getcode")
                tools.PrintMes("获取代码","green")
                checkout scm: [$class: 'GitSCM', branches: [[name: "${branchName}"]], 
                        doGenerateSubmoduleConfigurations: false, 
                        extensions: [], 
                        submoduleCfg: [], 
                        userRemoteConfigs: [[credentialsId: 'gitee', url: "${GIT_URL}"]]
                ]
            }
        }
        
        sh 'ls -l'
        sh 'id'
    }

    stage('SONAR') {
        sh '''
            echo ${_version}
            echo ${work_directory}
        '''
    }

    stage('BUILD') {
        sh "export JAVA_HOME=${JAVA_HOME}"
        sh 'echo $JAVA_HOME'
        sh 'mvn clean package -Dmaven.test.skip=true -U -Dmaven.javadoc.skip=true'
    }

    stage('DOCKER') {
        // Docker 构建逻辑
    }

    stage('DEPLOY') {
        // 部署逻辑
    }

    stage('ARCHIVE') {
        // 制品库上传逻辑
    }
    
}